﻿/**
* Vista asociada al contenido 
* del tab de la funcionalidad VER LISTADO DE DOCUMENTOS->DETALLE DEL DOCUMENTO
* en el aplicativo.
*/
Ext.define('entgpv11.view.details.SourceView', {
    extend: 'Ext.Panel',
    xtype: 'sourceview',
    //requires: [
    //    'Ext.ux.SimpleIFrame'],
    config:
    {
        cls: 'ux-code',
        styleHtmlContent: false,
        //scroll: 'both',
        floating: true,
        //autoScroll: true,
        scrollable: {
            direction: 'both',
            directionLock: true
        },
        //centered: true,
        width: '100%',
        height: '100%'

    },
    initialize: function () {
        try {
            //this.applyScrollable({ direction: 'horizontal', directionLock: true });

        } catch (ex) {
            APP_GLOBAL.SetLog('DocList.initialize::' + ex);
        }
    },
  cleanWordClipboard:function (input) {
        var swapCodes   = new Array(8211, 8212, 8216, 8217, 8220, 8221, 8226, 8230); // dec codes from char at
        var swapStrings = new Array("--", "--", "'",  "'",  "\"",  "\"",  "*",  "...");  

        // debug for new codes
        // for (i = 0; i < input.length; i++)  alert("'" + input.charAt(i) + "': " + input.charCodeAt(i));    
        var output = input;
        for (i = 0; i < swapCodes.length; i++) {
            var swapper = new RegExp("\\u" + swapCodes[i].toString(16), "g"); // hex codes
            output = output.replace(swapper, swapStrings[i]);
        }
        return output;
     },
    setViewHtml: function (data_txt, html_link) {
    
        var w = window.innerWidth;
        var h = window.innerHeight;
        
        this.setMasked(true);
        this.setHtml('<center>Cargando Documento...</center>');

        var v = '<div class="x-scroll-container"><iframe src="' + html_link + '" width=\"90%\" height=\"90%\" scrolling="no" frameborder="0" ></iframe></div>';
        var ifSetHml = false;

        var extList = html_link.split(".");
        if (extList.length > 0) {
            if (extList[extList.length - 1] == 'txt') {
                v = '<pre>' + data_txt + '</pre>';
                this.setHtml(v);
                ifSetHml = true;
            }
            if (extList[extList.length - 1] == 'doc') {
                v = '<pre>' + this.cleanWordClipboard(data_txt) + '</pre>';
                this.setHtml(v);
                ifSetHml = true;
            }         
        }
        if (!ifSetHml) {
            //overflow:auto;
            v = '<iframe id="iframe-' + this.id + '"' +
            ' height="'+h+'" width="'+w+'" scrolling="no" ' +
            ' style="border:none;" ' +
            ' src="' + html_link + '"' +
            '></iframe>';
            this.setHtml(v);

        }

        this.setMasked(false);
       

    }
});